<?php 
	include_once 'dataservice.php';
	include_once 'thuvienham.php';

	class diemdanh_db 
	{
		public function Them($MaBuoiHoc, $MaLopHoc, $MaHocVien)
		{
			$sql = "INSERT INTO `tbl_diemdanh`(`MaBuoiHoc`, `MaLopHoc`, `MaHocVien`)
					VALUES ('$MaBuoiHoc', '$MaLopHoc', '$MaHocVien')";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function Xoa($MaBuoiHoc)
		{
			$sql = "DELETE FROM `tbl_diemdanh` WHERE `MaBuoiHoc` = '$MaBuoiHoc'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		public function XoaLopHoc($MaLopHoc)
		{
			$sql = "DELETE FROM `tbl_diemdanh` WHERE `MaLopHoc` = '$MaLopHoc'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function XoaHocVien($MaHocVien)
		{
			$sql = "DELETE FROM `tbl_diemdanh` WHERE `MaHocVien` = '$MaHocVien'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function CapNhat($MaBuoiHoc, $MaLopHoc, $MaHocVien)
		{
			$sql = "UPDATE `tbl_diemdanh`
					SET `MaLopHoc` = '$MaLopHoc', `MaHocVien` = '$MaHocVien'
					WHERE `MaBuoiHoc` = '$MaBuoiHoc'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function LayDanhSach($MaBuoiHoc, $MaLopHoc, $MaHocVien)
		{
			$sql = "SELECT * FROM `tbl_diemdanh` WHERE 1  ";
			if($MaBuoiHoc != -1)
				$sql .= " AND `MaBuoiHoc` = '$MaBuoiHoc' ";

			if($MaLopHoc != "")
				$sql .= " AND `MaLopHoc` = '$MaLopHoc' ";

			if($MaHocVien != "")
				$sql .= " AND `MaHocVien` = '$MaHocVien' ";

			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}

	}

